package net.wanho.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.dto.ProductDTO;
import net.wanho.entity.Product;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-12-13 9:32
 * Description：<描述>
 */
@RestController
@RequestMapping("/products")
@Api(tags = "02.商品模块")
public class ProductController {

    @ApiOperation("商品列表")
    @GetMapping
    public AjaxResult list(){
        List<Product> list = new ArrayList<>();
        list.add(new Product(1001, "aa", 12.3, 20.4));
        list.add(new Product(1002, "bb", 13.3, 21.4));
        list.add(new Product(1003, "cc", 14.3, 22.4));
        return AjaxResult.success(list);
    }

    @ApiOperation("根据id查询商品")
    @GetMapping("/{id}")
    public AjaxResult findById(@PathVariable Integer id){
        return AjaxResult.success("查询成功", new Product(id, "aa", 12.3, 20.4));
    }

    @ApiOperation("根据查询查询商品")
    @GetMapping("/query")
    public AjaxResult query(@ApiParam("查询条件") Product product){
        List<Product> list = new ArrayList<>();
        list.add(new Product(1001, "aa", 12.3, 20.4));
        list.add(new Product(1002, "bb", 13.3, 21.4));
        list.add(new Product(1003, "cc", 14.3, 22.4));
        return AjaxResult.success(list);
    }

    @GetMapping("/findByCondition")
    public AjaxResult findByCondition(ProductDTO productDTO){
        List<Product> list = new ArrayList<>();
        list.add(new Product(1001, "aa", 12.3, 20.4));
        list.add(new Product(1002, "bb", 13.3, 21.4));
        list.add(new Product(1003, "cc", 14.3, 22.4));
        return AjaxResult.success(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody Product product){
        System.out.println(product);
        return AjaxResult.success();
    }

    @PutMapping
    public AjaxResult modify(@RequestBody Product product){
        System.out.println(product);
        return AjaxResult.success("修改成功");
    }

    @DeleteMapping("/{id}")
    public AjaxResult removeById(@PathVariable Integer id){
        System.out.println("删除id为" + id + "的商品");
        return AjaxResult.success("删除成功");
    }

    @DeleteMapping("/removeBatch")
    public AjaxResult removeBatch(@RequestBody List<Integer> ids){
        System.out.println(ids);
        return AjaxResult.success("批量删除成功");
    }

}
